var app=sm("do_App");
var page=sm("do_Page");
var nf=sm("do_Notification");
var config = require("config");
var cache=sm("do_DataCache");

var do_back=ui("do_back");
var do_ALayout_root=ui("do_ALayout_root");
var do_webviewalt=ui("do_webviewalt");
var do_company=ui("do_company");
var do_bank=ui("do_bank");
var do_label_1 = ui("do_Label_1");
var pagepar=page.getData(); 
do_back.on("touch",function(){	
	app.closePage();
});
page.on("back",function(){
	app.closePage();
});
//用于等待登录的过程
do_ALayout_root.add("loadingUI", "source://view/loadingUI.ui", 0, 0);
page.on("loaded",function(){
	do_label_1.text=pagepar.type;
	var nowdate=new Date();
	var olddate=nowdate.getTime();
	app.fire("tologin",{times:olddate,pagesize:3});
	do_company.border="000000FF,1,[10,0,0,10]";	
	do_bank.border="000000FF,1,[0,10,10,0]";
	loaddata();	
});	
function loaddata(){
	 var loadingUI = ui("loadingUI");
   //初始化隐藏遮盖
   loadingUI.visible = true;
	var http = mm("do_Http");	
	http.method = "POST";
	http.timeout = 10 * 1000;
	http.contentType = "application/json";
	http.url = config.baseUrl + "getbalance";
	var userinfo=cache.loadData("userinfo");
	http.body=JSON.stringify({balanceType:2,businesstype:pagepar.type,usernum:userinfo.usernum,userId:userinfo.userid});
	http.on("success", function(data) {
			if(data.result==1 && data.data && data.data.balanceList){
				do_webviewalt.add("bankwebview", "source://view/money/bankwebview.ui", 0, 1);
				loadingUI.visible = false;  
				var bankwebview=ui("bankwebview");
				var hashdata = mm("do_HashData");
				bankwebview.bindData(hashdata);
				hashdata.addData({
					"chartdata" : data.data
				});
				bankwebview.refreshData(); 
			}
			else if(data.result==3045){	
				loadingUI.visible = false;
				 app.closePage({data:"帐号可能被其它终端登录，请重新登录", animationType:"", layer:3});	
				 cache.saveData("userinfo", "");
			}
   		else{
   			 loadingUI.visible = false;
   			nf.toast(data.msg || "失败"); 
   		}
	});
	http.on("fail", function(data) {
		loadingUI.visible = false;
		nf.toast("网络异常");
	});
	http.request();
}
ui("do_company").on("touch",function(){
	app.closePage();
});